<template>
  <div class="app-container">
    <!-- 添加或修改报分组对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body v-drag-fullscreen>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="所属分类" prop="modelType">
          <el-select v-model="form.modelType" placeholder="请选择模块类型" :disabled="disabled">
            <el-option
              v-for="item in dict.report_model_type"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分组名称" prop="groupName">
          <el-input v-model="form.groupName" placeholder="请输入分组名称" :disabled="disabled"/>
        </el-form-item>
        <el-form-item label="排序序号" prop="orderNum">
          <el-input v-model="form.orderNum" placeholder="请输入排序序号" :disabled="disabled"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :disabled="disabled"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {getReportGroup, addReportGroup, updateReportGroup} from "@/api/ureport/reportGroup";

  export default {
    name: "ReportGroupFrom",
    dicts: ['report_model_type',],
    data() {
      return {
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        //是否禁用
        disabled: false,
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          modelType: [
            { required: true, message: "所属分类不能为空", trigger: "blur" }
          ],
          groupName: [
            { required: true, message: "分组名称不能为空", trigger: "blur" }
          ],
        },
        currentNode: {}
      };
    },
    created() {

    },
    methods: {
      show(option) {
        this.reset();
        this.currentNode = option.currentNode
        this.form.modelType = this.currentNode.id
        this.open = true;
        this.title = "新增分组";
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
        this.$emit("cancel")
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          modelType: null,
          groupName: null,
          orderNum: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null
        };
        this.resetForm("form");
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            addReportGroup(this.form).then(response => {
              this.msgSuccess("新增分组成功");
              this.open = false
              this.$emit("ok")
            });
          }
        });
      }
    }
  };
</script>
